<template>
  <div :class="className">
    <el-config-provider :locale="locale">
      <router-view />
    </el-config-provider>
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { ElConfigProvider } from 'element-plus'
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
import { useI18n } from 'vue-i18n'
import { dyncRoutes } from './utils/routes'
import { store } from './store'

export default defineComponent({
  components: {
    [ElConfigProvider.name]: ElConfigProvider,
  },
  data() {
    return {
      routeTree: [],
      locale: useI18n().locale.value == 'zh-cn' ? zhCn : '',
    }
  },
  created() {
    if (!localStorage.getItem('routes')) {
      console.log(localStorage.getItem('routes'))
      return
    } else {
      const routes = JSON.parse(localStorage.getItem('routes') as string)
      const accessedRoutes = dyncRoutes(JSON.parse(JSON.stringify(routes)))
      store.commit('SET_ROUTES', accessedRoutes)
      store.dispatch('GenerateRoutes')
    }
  },
  provide: function () {
    return {
      app: this,
    }
  },
  computed: {
    className() {
      return localStorage.getItem('className')
    },
  },
})
</script>
<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
